﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AmazonCommon.Amazon.ECS;


/// <summary>
/// Summary description for SalesOptimizer
/// </summary>
/// 
public class SalesOptimizer
{

    /// <summary>
    /// Returns Only Products with prices Set
    /// </summary>
    /// <param name="list"></param>
    /// <returns></returns>
    public static System.Collections.Generic.List<Item> ProcessReturnedItems(Item[] list)
    {
        List<Item> result = new System.Collections.Generic.List<Item>();
        foreach (Item item in list)
        {
            if (int.Parse(item.Offers.TotalOffers) > 0)
            {
                result.Add(item);
            }
        }
        if (result.Count < 4)
        {
            result.AddRange(list.ToArray());
        }
        return result;
    }


    public static string GetSortAttribute(string nodeName, string sort)
    {
        string result;
        result = "";
        if (nodeName != "All")
        {
            switch (sort)
            {
                case "maxprice":
                    result = GetSortAttributeForMaxPrice(nodeName);
                    break;
                case "minprice":
                    result = GetSortAttributeForMinPrice(nodeName);
                    break;
                case "salesrank":
                    result = GetSortAttributeForSalesRank(nodeName);
                    break;
                default:
                    result = GetSortAttributeForMaxPrice(nodeName);
                    break;
            }
        }
        return result;
    }

    private static string GetSortAttributeForSalesRank(string nodeName)
    {
        string result;
        result = string.Empty;
        switch (nodeName)
        {
            //case "DigitalMusic":
            //    result = "songtitlerank";
            //    break;
            case "Apparel":
                result = "salesrank";
                break;
            case "Grocery":
                result = "salesrank";
                break;
            case "Baby":
                result = "salesrank";
                break;
            case "Beauty":
                result = "salesrank";
                break;
            //case "Automotive":
            //    result = "inverseprice";
            //    break;
            //case "HealthPersonalCare":
            //    result = "salesrank";
            //    break;
            //case "Jewelry":
            //    result = "inverseprice";
            //    break;
            //case "Merchants":
            //    result = "salesrank";
            //    break;
            //case "MusicTracks":
            //    result = "-titlerank";
            //    break;
            //case "SportingGoods":
            //    result = "inverseprice";
            //    break;
            //case "Wireless":
            //    result = "inverse-pricerank";
            //    break;
            //case "WirelessAccessories":
            //    result = "psrank";
            //    break;
            case "DigitalMusic":
                result = "songtitlerank";
                break;
            default:
                result = "salesrank";
                break;
        }
        return result;
    }

    private static string GetSortAttributeForMinPrice(string nodeName)
    {
        throw new NotImplementedException();
    }

    private static string GetSortAttributeForMaxPrice(string nodeName)
    {
        string result;
        result = string.Empty;
        switch (nodeName)
        {

            case "All":
                result = null;
                break;
            case "Apparel":
                result = "inverseprice";
                break;
            case "Automotive":
                result = "-price";
                break;
            case "Baby":
                result = "-price";
                break;
            case "Beauty":
                result = "-price";
                break;
            case "Books":
                result = "inverse-pricerank";
                break;
            case "Classical":
                result = "-price";
                break;
            case "DigitalMusic":
                result = "songtitlerank";
                break;
            case "DVD":
                result = "-price";
                break;
            case "Electronics":
                result = "-price";
                break;
            case "GourmetFood":
                result = "inverseprice";
                break;
            case "Grocery":
                result = "inverseprice";
                break;
            case "HealthPersonalCare":
                result = "inverseprice";
                break;
            case "HomeGarden":
                result = "-price";
                break;
            case "Industrial":
                result = "-price";
                break;
            case "Jewelry":
                result = "inverseprice";
                break;
            case "KindleStore":
                result = "-price";
                break;
            case "Kitchen":
                result = "-price";
                break;
            case "Magazines":
                result = "-price";
                break;
            case "Merchants":
                result = "inverseprice";
                break;
            case "Miscellaneous":
                result = "-price";
                break;
            case "MP3Downloads":
                result = "-price";
                break;
            case "Music":
                result = "-price";
                break;
            case "Watches":
                result = "-price";
                break;
            case "Wireless":
                result = "inverse-pricerank";
                break;
            case "WirelessAccessories":
                result = "psrank";
                break;
            case "SportingGoods":
                result = "inverseprice";
                break;
            default:
                result = "-price";
                break;
        }
        return result;
    }

    internal static string GetSecondSortAttribute(string nodeName)
    {

        string result;
        result = "";
        if (nodeName != "All")
        {
            switch (nodeName)
            {
                case "DigitalMusic":
                    result = "uploaddaterank";
                    break;
                case "MusicTracks":
                    result = "titlerank";
                    break;
                case "Wireless":
                    result = "inverse-pricerank";
                    break;
                default:
                    result = "salesrank";
                    // itemSearchRequest.MinimumPrice = 5;
                    break;
            }
        }
        return result;
    }
}
